package animation

import (
	"net/http"
	"strconv"

	M "ICan/MySql"
	"ICan/errmsg"
	_ "github.com/go-sql-driver/mysql"
	"github.com/gin-gonic/gin"
)
type animation struct {
	Id string `json:"id"`
	Img string `json:"img"`
	Name string `json:"name"`
	Alais string `json:"alais"`
	Type string `json:"type"`
	Synopsis string `json:"synopsis"`
 	Years string `json:"years"`
	Region string `json:"region"`
	Lndexes string `json:"lndexes"`
	Label string `json:"label"`
	Num string `json:"num"`
	Introduction string `json:"introduction"`
	Numhas string `json:"numhas"`
	Give_up_num string `json:"give_up_num"`
}
type length struct {
	Length int `json:"length"`
}
type id struct {
	id string
}
func Search(ctx *gin.Context){
	name := ctx.PostForm("name")
	na := "%"+name+"%"
	page := ctx.PostForm("page")
	pa, _ := strconv.Atoi(page)
	var num_a int
	var num_b int
	if pa > 1 {
		num_a = (pa-1) * 9 + 1
	}else {
		num_a = 0
	}
	num_b = 9
	sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where name like ? limit ?,?`
	rows, _ := M.Db.Query(sqlstr, na, num_a,num_b)
	defer rows.Close()
	var ani = make([]animation,0)
	for rows.Next() {
		var u animation
		rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
		ani = append(ani, animation{
			Id:u.Id,
			Img:u.Img,
			Name:u.Name,
			Alais:u.Alais,
			Type:u.Type,
			Synopsis:u.Synopsis,
			Years:u.Years,
			Region:u.Region,
			Lndexes:u.Lndexes,
			Label:u.Label,
			Num:u.Num,
			Introduction:u.Introduction,
			Numhas:u.Numhas,
			Give_up_num:u.Give_up_num,

		})
	}
	sqlstr2 := `select count(*) from animation where name like ?`
	rows2 := M.Db.QueryRow(sqlstr2, na)
	var ani2 length
	rows2.Scan(&ani2.Length)
	code := errmsg.Succse
	data := map[string]interface{}{
		"code":code,
		"msg":errmsg.GetErrMSg(code),
		"data":ani,
		"length":ani2.Length,
	}
	ctx.JSON(http.StatusOK, data)
}
func Find(ctx *gin.Context){
	name := ctx.PostForm("type")
	na := "%"+name+"%"
	page := ctx.PostForm("page")
	pa, _ := strconv.Atoi(page)
	var num_a int
	var num_b int
	if pa > 1 {
		num_a = (pa-1) * 9 + 1
	}else {
		num_a = 0
	}
	num_b = 9
	sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where type like ? limit ?,?`
	rows, _ := M.Db.Query(sqlstr, na,num_a,num_b)
	defer rows.Close()
	var ani = make([]animation,0)
	for rows.Next() {
		var u animation
		rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
		ani = append(ani, animation{
			Id:u.Id,
			Img:u.Img,
			Name:u.Name,
			Alais:u.Alais,
			Type:u.Type,
			Synopsis:u.Synopsis,
			Years:u.Years,
			Region:u.Region,
			Lndexes:u.Lndexes,
			Label:u.Label,
			Num:u.Num,
			Introduction:u.Introduction,
			Numhas:u.Numhas,
			Give_up_num:u.Give_up_num,

		})
	}
	sqlstr2 := `select count(*) from animation where type like ?`
	rows2 := M.Db.QueryRow(sqlstr2, na)
	var ani2 length
	rows2.Scan(&ani2.Length)
	code := errmsg.Succse
	data := map[string]interface{}{
		"code":code,
		"msg":errmsg.GetErrMSg(code),
		"data":ani,
		"length":ani2.Length,
	}
	ctx.JSON(http.StatusOK, data)
}

func History(ctx *gin.Context){
	user_id := ctx.PostForm("user_id")
	ani_id := ctx.PostForm("animation_id")
	num := ctx.PostForm("num")
	time := ctx.PostForm("time")
	sqlstr := `insert into history valuse (?, ?, ?, ?)`
	res, _ := M.Db.Exec(sqlstr, user_id, ani_id, num, time)
	res.LastInsertId()
	code := errmsg.Succse
	data := map[string]interface{}{
		"code":code,
		"msg":errmsg.GetErrMSg(code),
	}
	ctx.JSON(http.StatusOK, data)
}

func Collection(ctx * gin.Context){
	user_id := ctx.PostForm("user_id")
	ani_id := ctx.PostForm("animation_id")
	sqlstr := `insert into collection values (?, ?)`
	res, _ := M.Db.Exec(sqlstr, user_id, ani_id)
	res.LastInsertId()
	code := errmsg.Succse
	data := map[string]interface{}{
		"code":code,
		"msg":errmsg.GetErrMSg(code),
	}
	ctx.JSON(http.StatusOK, data)
}
func Ren_up(ctx *gin.Context){
	var a = make([]id, 0)
	var ani = make([]animation,0)
	sqlstr := `select * from recent_updata limit 0,3`
	rows, _ := M.Db.Query(sqlstr)
	defer rows.Close()
	for rows.Next(){
		var b id
		rows.Scan(&b.id)
		a = append(a, id{
			id:b.id,
		})
	}
	for _, v := range a {
		var u animation
		sqlstr2 := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where id = ?`
		res := M.Db.QueryRow(sqlstr2, v.id)
		res.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
		ani = append(ani, animation{
			Id:u.Id,
			Img:u.Img,
			Name:u.Name,
			Alais:u.Alais,
			Type:u.Type,
			Synopsis:u.Synopsis,
			Years:u.Years,
			Region:u.Region,
			Lndexes:u.Lndexes,
			Label:u.Label,
			Num:u.Num,
			Introduction:u.Introduction,
			Numhas:u.Numhas,
			Give_up_num:u.Give_up_num,

		})
		
	}
	var a1 = make([]id, 0)
	var ani1 = make([]animation,0)
	sqlstr1 := `select * from recent_updata limit 0,3`
	rows, _ = M.Db.Query(sqlstr1)
	defer rows.Close()
	for rows.Next(){
		var b id
		rows.Scan(&b.id)
		a1 = append(a1, id{
			id:b.id,
		})
	}
	for _, v := range a1 {
		var u animation
		sqlstr2 := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where id = ?`
		res := M.Db.QueryRow(sqlstr2, v.id)
		res.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
		ani1 = append(ani1, animation{
			Id:u.Id,
			Img:u.Img,
			Name:u.Name,
			Alais:u.Alais,
			Type:u.Type,
			Synopsis:u.Synopsis,
			Years:u.Years,
			Region:u.Region,
			Lndexes:u.Lndexes,
			Label:u.Label,
			Num:u.Num,
			Introduction:u.Introduction,
			Numhas:u.Numhas,
			Give_up_num:u.Give_up_num,

		})
		
	}
	sqlstr2 := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where type like ? limit 0,3`
	rows, _ = M.Db.Query(sqlstr2, "%校园%")
	defer rows.Close()
	var ani2 = make([]animation,0)
	for rows.Next() {
		var u animation
		rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
		ani2 = append(ani2, animation{
			Id:u.Id,
			Img:u.Img,
			Name:u.Name,
			Alais:u.Alais,
			Type:u.Type,
			Synopsis:u.Synopsis,
			Years:u.Years,
			Region:u.Region,
			Lndexes:u.Lndexes,
			Label:u.Label,
			Num:u.Num,
			Introduction:u.Introduction,
			Numhas:u.Numhas,
			Give_up_num:u.Give_up_num,

		})
	}
	sqlstr3 := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where type like ? limit 0,3`
	rows, _ = M.Db.Query(sqlstr3, "%搞笑%")
	defer rows.Close()
	var ani3 = make([]animation,0)
	for rows.Next() {
		var u animation
		rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
		ani3 = append(ani3, animation{
			Id:u.Id,
			Img:u.Img,
			Name:u.Name,
			Alais:u.Alais,
			Type:u.Type,
			Synopsis:u.Synopsis,
			Years:u.Years,
			Region:u.Region,
			Lndexes:u.Lndexes,
			Label:u.Label,
			Num:u.Num,
			Introduction:u.Introduction,
			Numhas:u.Numhas,
			Give_up_num:u.Give_up_num,

		})
	}
	sqlstr4 := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where type like ? limit 0,3`
	rows, _ = M.Db.Query(sqlstr4, "%青春%")
	defer rows.Close()
	var ani4 = make([]animation,0)
	for rows.Next() {
		var u animation
		rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
		ani4 = append(ani4, animation{
			Id:u.Id,
			Img:u.Img,
			Name:u.Name,
			Alais:u.Alais,
			Type:u.Type,
			Synopsis:u.Synopsis,
			Years:u.Years,
			Region:u.Region,
			Lndexes:u.Lndexes,
			Label:u.Label,
			Num:u.Num,
			Introduction:u.Introduction,
			Numhas:u.Numhas,
			Give_up_num:u.Give_up_num,

		})
	}
	sqlstr5 := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where type like ? limit 0,3`
	rows, _ = M.Db.Query(sqlstr5, "%战争%")
	defer rows.Close()
	var ani5 = make([]animation,0)
	for rows.Next() {
		var u animation
		rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
		ani5 = append(ani5, animation{
			Id:u.Id,
			Img:u.Img,
			Name:u.Name,
			Alais:u.Alais,
			Type:u.Type,
			Synopsis:u.Synopsis,
			Years:u.Years,
			Region:u.Region,
			Lndexes:u.Lndexes,
			Label:u.Label,
			Num:u.Num,
			Introduction:u.Introduction,
			Numhas:u.Numhas,
			Give_up_num:u.Give_up_num,

		})
	}
	code := errmsg.Succse
	data := map[string]interface{}{
		"code":code,
		"msg":errmsg.GetErrMSg(code),
		"Recent_updata":ani,
		"Comment":ani1,
		"School":ani2,
		"Happy":ani3,
		"Youth":ani4,
		"Warfare":ani5,
	}
	ctx.JSON(http.StatusOK, data)
}
func Type(ctx *gin.Context){
	var ani = make([]animation, 0)
	page := ctx.PostForm("page")
	pa, _ := strconv.Atoi(page)
	var num_a int
	var num_b int
	if pa > 1 {
		num_a = (pa-1) * 9 + 1
	}else {
		num_a = 0
	}
	num_b = 9
	var ani2 length
	region := ctx.PostForm("region")
	time := ctx.PostForm("time")
	language := ctx.PostForm("language")
	typea := ctx.PostForm("type")
	ty := "%"+typea+"%"
	a := "全部"
	if region != a && time != a && language != a && typea != a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where region = ? and years = ? and label = ? and type like ? limit ?,?`
		rows, _ := M.Db.Query(sqlstr, region, time, language, ty, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,		
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation where region = ? and years = ? and label = ? and type like ?`
		rows2 := M.Db.QueryRow(sqlstr2, region, time, language, ty)
		rows2.Scan(&ani2.Length)
	}
	if region == a && time != a && language != a && typea != a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where years = ? and label = ? and type like ? limit ?,?`
		rows, _ := M.Db.Query(sqlstr, time, language, ty, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,		
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation where years = ? and label = ? and type like ?`
		rows2 := M.Db.QueryRow(sqlstr2, time, language, ty)
		rows2.Scan(&ani2.Length)
	}
	if region != a && time == a && language != a && typea != a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where region = ? and label = ? and type like ? limit ?,?`
		rows, _ := M.Db.Query(sqlstr, region, language, ty, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,			
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation where region = ? and label = ? and type like ?`
		rows2 := M.Db.QueryRow(sqlstr2, region, language, ty)
		rows2.Scan(&ani2.Length)
	}
	if region != a && time != a && language == a && typea != a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where years = ? and region = ? and type like ? limit ?,?`
		rows, _ := M.Db.Query(sqlstr, time, region, ty, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,				
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation where years = ? and region = ? and type like ?`
		rows2 := M.Db.QueryRow(sqlstr2, time, region, ty)
		rows2.Scan(&ani2.Length)
	}
	if region != a && time != a && language != a && typea == a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where years = ? and label = ? and region = ? limit ?,?`
		rows, _ := M.Db.Query(sqlstr, time, language,region, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,			
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation where years = ? and label = ? and region = ?`
		rows2 := M.Db.QueryRow(sqlstr2, time, language,region)
		rows2.Scan(&ani2.Length)
	}
	if region == a && time == a && language != a && typea != a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where label = ? and type like ? limit ?,?`
		rows, _ := M.Db.Query(sqlstr, language,ty, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,				
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation where label = ? and type like ?`
		rows2 := M.Db.QueryRow(sqlstr2, language, ty)
		rows2.Scan(&ani2.Length)
	}
	if region == a && time != a && language == a && typea != a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where years = ? and type like ? limit ?,?`
		rows, _ := M.Db.Query(sqlstr, time, ty, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,				
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation where years = ? and type like ?`
		rows2 := M.Db.QueryRow(sqlstr2, time, ty)
		rows2.Scan(&ani2.Length)
	}
	if region == a && time != a && language != a && typea == a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where years = ? and label = ? limit ?,?`
		rows, _ := M.Db.Query(sqlstr, time, language, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,				
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation where where years = ? and label = ?`
		rows2 := M.Db.QueryRow(sqlstr2, time, language)
		rows2.Scan(&ani2.Length)
	}
	if region != a && time == a && language == a && typea != a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where region = ? and type like ? limit ?,?`
		rows, _ := M.Db.Query(sqlstr, region, ty, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,				
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation where region = ? and type like ?`
		rows2 := M.Db.QueryRow(sqlstr2, region, ty)
		rows2.Scan(&ani2.Length)
	}
	if region != a && time == a && language != a && typea == a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where region = ? and label = ? limit ?,?`
		rows, _ := M.Db.Query(sqlstr, region, language, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,				
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation where region = ? and label = ?`
		rows2 := M.Db.QueryRow(sqlstr2, region, language)
		rows2.Scan(&ani2.Length)
	}
	if region != a && time != a && language == a && typea == a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where years = ? and region = ? limit ?,?`
		rows, _ := M.Db.Query(sqlstr, time, region, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,		
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation where years = ? and region = ?`
		rows2 := M.Db.QueryRow(sqlstr2, time, region)
		rows2.Scan(&ani2.Length)
	}
	if region == a && time == a && language == a && typea != a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where type like ? limit ?,?`
		rows, _ := M.Db.Query(sqlstr, ty, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,			
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation where type like ?`
		rows2 := M.Db.QueryRow(sqlstr2, ty)
		rows2.Scan(&ani2.Length)
	}
	if region == a && time == a && language != a && typea == a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where label = ? limit ?,?`
		rows, _ := M.Db.Query(sqlstr, language, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,				
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation where label = ?`
		rows2 := M.Db.QueryRow(sqlstr2, language)
		rows2.Scan(&ani2.Length)
	}
	if region != a && time == a && language == a && typea == a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where region = ? limit ?,?`
		rows, _ := M.Db.Query(sqlstr, region, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,			
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation where region = ?`
		rows2 := M.Db.QueryRow(sqlstr2, region)
		rows2.Scan(&ani2.Length)
	}
	if region == a && time != a && language == a && typea == a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where years = ? limit ?,?`
		rows, _ := M.Db.Query(sqlstr, time, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,			
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation where years = ?`
		rows2 := M.Db.QueryRow(sqlstr2, time)
		rows2.Scan(&ani2.Length)
	}
	if region == a && time == a && language == a && typea == a{
		sqlstr := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation limit ?,?`
		rows, _ := M.Db.Query(sqlstr, num_a, num_b)
		defer rows.Close()
		for rows.Next() {
			var u animation
			rows.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
			ani = append(ani, animation{
				Id:u.Id,
				Img:u.Img,
				Name:u.Name,
				Alais:u.Alais,				
				Type:u.Type,
				Synopsis:u.Synopsis,
				Years:u.Years,
				Region:u.Region,
				Lndexes:u.Lndexes,
				Label:u.Label,
				Num:u.Num,
				Introduction:u.Introduction,
				Numhas:u.Numhas,
				Give_up_num:u.Give_up_num,

			})
		}
		sqlstr2 := `select count(*) from animation`
		rows2 := M.Db.QueryRow(sqlstr2)
		rows2.Scan(&ani2.Length)
	}
	code := errmsg.Succse
	data := map[string]interface{}{
		"code":code,
		"msg":errmsg.GetErrMSg(code),
		"data":ani,
		"length":ani2.Length,
	}
	ctx.JSON(http.StatusOK, data)
}

func Paihang(ctx *gin.Context){
	sql1 := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where region = ? order by volume_num desc limit 0,10`
	rows1, _ := M.Db.Query(sql1, "美国")
	var ani1 = make([]animation, 0)
	defer rows1.Close()
	for rows1.Next() {
		var u animation
		rows1.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
		ani1 = append(ani1, animation{
			Id:u.Id,
			Img:u.Img,
			Name:u.Name,
			Alais:u.Alais,
			Type:u.Type,
			Synopsis:u.Synopsis,
			Years:u.Years,
			Region:u.Region,
			Lndexes:u.Lndexes,
			Label:u.Label,
			Num:u.Num,
			Introduction:u.Introduction,
			Numhas:u.Numhas,
			Give_up_num:u.Give_up_num,

		})
	}
	var ani2 = make([]animation, 0)
	sql2 := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where region = ? order by volume_num desc limit 0,10`
	rows2, _ := M.Db.Query(sql2, "大陆")
	defer rows2.Close()
	for rows2.Next() {
		var u animation
		rows2.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
		ani2 = append(ani2, animation{
			Id:u.Id,
			Img:u.Img,
			Name:u.Name,
			Alais:u.Alais,
			Type:u.Type,
			Synopsis:u.Synopsis,
			Years:u.Years,
			Region:u.Region,
			Lndexes:u.Lndexes,
			Label:u.Label,
			Num:u.Num,
			Introduction:u.Introduction,
			Numhas:u.Numhas,
			Give_up_num:u.Give_up_num,

		})
	}
	var ani3 = make([]animation, 0)
	sql3 := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where region = ? order by volume_num desc limit 0,10`
	rows3, _ := M.Db.Query(sql3, "日本")
	defer rows3.Close()
	for rows3.Next() {
		var u animation
		rows3.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
		ani3 = append(ani3, animation{
			Id:u.Id,
			Img:u.Img,
			Name:u.Name,
			Alais:u.Alais,
			Type:u.Type,
			Synopsis:u.Synopsis,
			Years:u.Years,
			Region:u.Region,
			Lndexes:u.Lndexes,
			Label:u.Label,
			Num:u.Num,
			Introduction:u.Introduction,
			Numhas:u.Numhas,
			Give_up_num:u.Give_up_num,

		})
	}
	var ani4 = make([]animation, 0)
	sql4 := `select id,img,name,alias,type,synopsis,years,region,lndexes,label,num,introduction,numhas,give_up_num from animation where region = ? order by volume_num desc limit 0,10`
	rows4, _ := M.Db.Query(sql4, "英国")
	defer rows4.Close()
	for rows4.Next() {
		var u animation
		rows4.Scan(&u.Id,&u.Img,&u.Name,&u.Alais,&u.Type,&u.Synopsis,&u.Years,&u.Region,&u.Lndexes,&u.Label,&u.Num,&u.Introduction,&u.Numhas,&u.Give_up_num)
		ani4 = append(ani4, animation{
			Id:u.Id,
			Img:u.Img,
			Name:u.Name,
			Alais:u.Alais,
			Type:u.Type,
			Synopsis:u.Synopsis,
			Years:u.Years,
			Region:u.Region,
			Lndexes:u.Lndexes,
			Label:u.Label,
			Num:u.Num,
			Introduction:u.Introduction,
			Numhas:u.Numhas,
			Give_up_num:u.Give_up_num,

		})
	}
	code := errmsg.Succse
	data := map[string]interface{}{
		"code":code,
		"msg":errmsg.GetErrMSg(code),
		"ani1":ani1,
		"ani2":ani2,
		"ani3":ani3,
		"ani4":ani4,
	}
	ctx.JSON(http.StatusOK, data)
}

